<template>
  <div>
    <el-table
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange"
      border
    >
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column prop="mainteId" label="维保类型" align="center"> </el-table-column>
      <el-table-column prop="orderNum" label="计划类型" align="center"> </el-table-column>
      <el-table-column prop="planId" label="工单编号" align="center"> </el-table-column>
      <el-table-column prop="mainteDate" label="维保日期" align="center"> </el-table-column>
      <el-table-column prop="isDelete" label="工单状态" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.isDelete == true" style="color: green"
            >已审核</span
          >
          <span v-if="scope.row.isDelete == false" style="color: red"
            >已驳回</span
          >
        </template>
      </el-table-column>
      <el-table-column prop="auditor" label="审核人员" align="center"> </el-table-column>
      <el-table-column prop="auditTime" label="审核时间" align="center"> </el-table-column>
      <el-table-column prop="auditRemarks" label="审核备注" align="center"> </el-table-column>
      <el-table-column prop="remark" label="维保备注" align="center"> </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.isDelete == true">
            <el-link type="danger" @click="bohui(scope.row)">驳回</el-link>
          </span>
          <span v-else>
            <el-link type="success" @click="shenhe(scope.row)">审核</el-link>
          </span>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="ruleFormData.pageIndex"
      :page-sizes="[2, 4, 6, 8]"
      :page-size="ruleFormData.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="count"
    >
    </el-pagination>
  </div>
</template>

<script>
import {
  GetCount,
  GetRepairOrderPage,
  PutRepairOrder,
} from "@/api/assetManagecopy/RepairOrder";

export default {
  data() {
    return {
      ruleFormData: {
        pageIndex: 1,
        pageSize: 6,
      },
      count: 0,
      countnum: 0,
      //显示的数据
      tableData: [],
      multipleSelection: [],
      ids: [],
    };
  },
  created() {
    this.ListData();
    this.totalcount();
  },
  methods: {
    //获取总条数方法
    totalcount() {
      GetCount().then((res) => {
        this.countnum = res.data;
      });
    },
    totalcount() {
      GetTotaocount().then((res) => {
        this.countnum = res.data;
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleSizeChange(val) {
      this.ruleFormData.pageSize = val;
      this.ListData();
    },
    handleCurrentChange(val) {
      this.ruleFormData.pageIndex = val;
      this.ListData();
    },
    //显示方法
    ListData() {
      GetRepairOrderPage(this.ruleFormData).then((res) => {
        this.tableData = res.data.data;
        this.count = res.data.totalCount;
      });
    },
    //表格显示具体时间
    formatDate(row, column) {
      // 获取单元格数据
      let data = row[column.property];
      if (data == null) {
        return 1;
      }
      let dt = new Date(data);
      return (
        dt.getFullYear() +
        "-" +
        (dt.getMonth() + 1) +
        "-" +
        dt.getDate() +
        " " +
        dt.getHours() +
        ":" +
        dt.getMinutes() +
        ":" +
        dt.getSeconds()
      );
    },
    //驳回
    bohui(row) {
      row.isDelete = false;
      PutRepairOrder(row).then((res) => {
        if (res.data) this.ListData();
      });
    },
    //审核
    shenhe(row) {
      row.isDelete = true;
      PutRepairOrder(row).then((res) => {
        if (res.data) this.ListData();
      });
    },
  },
};
</script>